package com.itwill.ecom.boardReply;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.itwill.ecom.board.BoardDaoImpl;

@Repository("boardReplyService")
public class BoardReplyServiceImpl implements BoardReplyService {
	@Autowired
	private BoardReplyDao boardReplyDao;
	
	public BoardReplyServiceImpl() {
		System.out.println("#### BoardReplyService()");
	}

	public BoardReplyServiceImpl(BoardReplyDao boardReplyDao) {
		System.out.println("#### BoardReplyService(BoardReplyDao boardReplyDao)");
		this.boardReplyDao = boardReplyDao;
	}

	public void setBoardReplyDao(BoardReplyDao boardReplyDao) {
		System.out.println("#### BoardReplyService : setBoardReplyDao(BoardReplyDao boardReplyDao)");
		this.boardReplyDao = boardReplyDao;
	}

	private BoardReplyDao getBoardReplyDao() {
		System.out.println("#### BoardReplyService : getBoardReplyDao()");
		return this.boardReplyDao;
	}

	@Override
	public boolean createReply(BoardReplyBeans reply){
		boolean result = false;
		
		try{
			getBoardReplyDao().create(reply);
			result = true;
		}
		catch(Exception e){
			System.out.println(e.getMessage());
		}
		
		return result;
	}

	@Override
	public List<BoardReplyBeans> getReplyByBoardNo(int boardno){
		List<BoardReplyBeans> resultList = new ArrayList<BoardReplyBeans>();
		
		try{
			resultList = getBoardReplyDao().readByBoardNo(boardno);
		}
		catch(Exception e){
			System.out.println(e.getMessage());
		}
		
		return resultList;
	}
	
	@Override
	public boolean updateContent(HashMap<String, String> contentMap){
		boolean result = false;
		
		try{
			getBoardReplyDao().updateContent(contentMap);
			result = true;
		}
		catch(Exception e){
			System.out.println(e.getMessage());
		}
		
		return result;
	}

	@Override
	public boolean updateRecommend(int replyno){
		boolean result = false;
		
		try{
			getBoardReplyDao().updateRecommend(replyno);
			result = true;
		}
		catch(Exception e){
			System.out.println(e.getMessage());
		}
		
		return result;
	}

	@Override
	public boolean delete(int replyno){
		boolean result = false;
		
		try{
			getBoardReplyDao().delete(replyno);
			result = true;
		}
		catch(Exception e){
			System.out.println(e.getMessage());
		}
		
		return result;
	}
}